﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace ECommerce.Shared.Models.Dtos;

/// <summary>
/// 用户信息DTO（前后端传输用）
/// </summary>
public class UserDto
{
    /// <summary>
    /// 用户唯一标识
    /// </summary>
    [JsonPropertyName("id")]
    public Guid Id { get; set; }

    /// <summary>
    /// 用户名（显示用）
    /// </summary>
    [Required(ErrorMessage = "用户名不能为空")]
    [MaxLength(100, ErrorMessage = "用户名最长为100个字符")]
    [MinLength(1, ErrorMessage = "用户名不能为空字符串")]
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 用户邮箱（登录账号）
    /// </summary>
    [Required(ErrorMessage = "邮箱不能为空")]
    [EmailAddress(ErrorMessage = "邮箱格式不正确")]
    [MaxLength(255, ErrorMessage = "邮箱最长为255个字符")]
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;

    /// <summary>
    /// 用户角色列表
    /// </summary>
    [Required(ErrorMessage = "角色列表不能为空")]
    [MinLength(1, ErrorMessage = "用户至少需分配一个角色")]
    [JsonPropertyName("roles")]
    public List<string> Roles { get; set; } = new();
}
